package org.example.controller;


import org.example.model.Test;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
public class ResponseBodyController {

    @RequestMapping("/json")
    @ResponseBody
    public Object json(){
        //返回自定义类型
        Test t = new Test();
        t.setA(111);
        t.setB("bbb");
        return t;
    }


    @RequestMapping("/map")
    @ResponseBody
    public Object map(){
        //返回Map
        Map<String,Object> map = new HashMap<>();
        map.put("a",111);
        map.put("b","bbb");
        return map;
    }

    @RequestMapping("/list")
    @ResponseBody
    public Object list(){
        //返回Map
        //或者你也可以不这么写
//        List<Test> list = new ArrayList<>();
//        list.add(new Test(111,"aaa"));
//        list.add(new Test(222,"bbb"));
//        return list;
        return Arrays.asList(
                new Test(111,"aaa"),
                new Test(222,"bbb")
        );
    }
}
